@extends('admin.layouts.main_slight')
@section('content')

<style>
    body{padding: 10px;}
</style>
<?php

use App\Extend\Admin\Common\Html\EasyForm;

$easyForm = new EasyForm();
?>
<body>

<!-- 内容主体区域 -->
<div style="padding: 15px;">
	<?php
	$url = '';
	?>
	<form class="layui-form layui-form-pane1" method="post" action="<?php echo $url; ?>" lay-filter="first">
	@csrf
		<?php
		echo $easyForm->setRequire(true)->setLabel('老密码')->password('password');
		echo $easyForm->setRequire(true)->setLabel('新密码')->setVerify(['required','password_new'])->password('password_new');
        echo $easyForm->setRequire(true)->setLabel('确认新密码')->setVerify(['required','password_again'])->password('password_again');
        
		?>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="*">提交</button>
				<button onclick="closeIframe();" type="button" class="layui-btn">取消</button>
			</div>
		</div>
	</form>

	<br><br><br>

	<script>

		layui.use('form', function(){
			const $ = layui.$;
			const form = layui.form;

			//自定义验证规则
			form.verify({
                password_new: function(val) {
                    if(val.length < 6) {
                        return '新密码不能小于六位'
                    }
                },
                password_again: function(val, item) {
                    const passwordNew = $('input[name=password_new]').val();
                    if(val != passwordNew) {
                        return '两次新密码不一致'
                    }
                }
			});

			//监听提交
			form.on('submit(*)', function(data){
				$.post('<?php echo $url ?>' , data.field , function(d) {
					console.log(d.code);
					if(d.code != 0) {
						//返回失败
						layer.msg(d.msg);
						return false;
					}
					layer.msg('成功');
					setTimeout(function() {
						const index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
						parent.layer.close(index); //再执行关闭
                        window.top.location.href=""
					},1000);
				});
				return false;
			});

		});

	</script>
</div>

</body>

@endsection